from os import write
import requests
# import beautifulsoup4 as bs4
import json
import jsonpath

# 百度疫情数据https://voice.baidu.com/act/newpneumonia/newpneumonia/?from=osari_pc_3
# url = 'https://voice.baidu.com/newpneumonia/get?target=trend&isCaseIn=0&stage=publish'
url = 'https://voice.baidu.com/act/newpneumonia/newpneumonia/get?target=trend&isCaseIn=0&stage=publish'

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.204 Safari/537.36',
}

def main():
    response = requests.get(url=url, headers=headers).text
    with open(r'test.txt', 'w') as f:
        f.write(response)
    # print(response)
    # datas = json.loads(response)
    
    # for el in datas['data'][0:31]:
    #     province = jsonpath.jsonpath(el,'$..name')[0]
    #     date_list = jsonpath.jsonpath(el,'$..updateDate')[0]
    #     confirm_list = jsonpath.jsonpath(el,'$..data')[0]
    #     add_list = jsonpath.jsonpath(el, '$..data')[1]
    #     print(province,date_list,confirm_list,add_list)
    

if __name__ == '__main__':
    main()